import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../views/Login.vue'
//导入全局样式表
import 'element-ui/lib/theme-chalk/base.css';
import { message } from '../utils/resetMessage';

Vue.use(VueRouter)

const routes = [

]

const router = new VueRouter({
  routes: [{ path: '/', redirect: '/Login' },
  { path: '/login', component: Login },
  {
    path: '/home', component: () => import('../views/Home.vue'),
    children: [
      { path: '/serverManagement', component: () => import('../components/ServerManage.vue') },
      { path: '/dataAnalysis', component: () => import('../components/DataAnalysis.vue') },
      { path: '/userManagement', component: () => import('../components/UserManager.vue') },
      { path: '/loggerManagement', component: () => import('../components/LoggerManagement.vue') },
      { path: '/loggerList', component: () => import('../components/LoggerList.vue') },
      { path: '/uperApproval', component: () => import('../components/UperApproval.vue') }
    ]
  },
  ]
})
// 导航守卫
router.beforeEach((to, from, next) => {
  if (to.path === '/login') return next();
  //获取token
  const tokenStr = window.sessionStorage.getItem('SMTP_TOKEN');
  if (!tokenStr) {
    return next('/login');
  }
  next();
})
export default router
